﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Xml;
using IURIP;
using URIP.Abstractor;
using URIP.Tool;

namespace URIP.Factory
{
    /// <summary>
    /// Factory to create abstractor
    /// </summary>
    public class AbstractorFactory
    {
        static AbstractorFactory()
        {
            InitAbstractors();
        }
        /// <summary>
        /// The abstractor defined in the system
        /// </summary>
        private static Dictionary<string, Type> m_abstractors = new Dictionary<string, Type>();

        /// <summary>
        /// Initialize all default abstractors into a container.
        /// </summary>
        private static void InitAbstractors()
        {
            m_abstractors.Add("SharePointAbstractor", typeof(SharePointAbstractor));
            m_abstractors.Add("FileAbstractor", typeof(FileAbstractor));

            //@@ add all default abstractor here
        }
        /// <summary>
        /// Get a specified abstractor from the setting
        /// </summary>
        /// <param name="node"></param>
        /// <param name="task"></param>
        /// <returns></returns>
        public static IAbstractor GetAbstractor(XmlNode node, ITask task)
        {
            var res = Util.GetObjectForFactory<IAbstractor>(m_abstractors, node, task);
            if (res != null)
            {
                res.InitByConfiguration(node);
            }

            return res;
        }
    }
}
